﻿@model PaymentMethodEditModel
@{
	ViewBag.Title = string.Concat(T("Common.Edit"), " - ", (ViewBag.Title as string) ?? Model.SystemName);

	Html.AddScriptParts(true, "~/Administration/Content/telerik/js/2012.2.607/telerik.common.min.js");
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "payment-method-form" }))
{
	<div class="section-header">
		<div class="title">
			<img src="@Url.Content(Model.IconUrl)" alt="@Model.FriendlyName" />
			@ViewBag.Title
			<a href="@Url.Action("Providers", "Payment")">(@T("Admin.Common.BackToList"))</a>
		</div>
		<div class="options">
			@{ Html.RenderWidget("admin_button_toolbar_before"); }

			<button type="submit" name="save" value="save" class="btn btn-warning">
				<i class="fa fa-check"></i>
				<span>@T("Admin.Common.Save")</span>
			</button>
			<button type="submit" name="save" value="save-continue" class="btn btn-secondary">
				<span>@T("Admin.Common.SaveContinue")</span>
			</button>

			@{ Html.RenderWidget("admin_button_toolbar_after"); }
		</div>
	</div>
	
	@Html.ValidationSummary(false)
	@Html.HiddenFor(model => model.SystemName)

	@Html.SmartStore().TabStrip().Name("payment-method-edit").Style(TabsStyle.Material).Items(x =>
	{
		x.Add().Text(T("Admin.Common.General").Text).Content(TabGeneral()).Selected(true);
		x.Add().Text(T("Admin.Common.Restrictions").Text).Content(TabRestrictions());
		x.Add().Text(T("Admin.Common.Stores").Text).Content(TabStores());

		EngineContext.Current.Resolve<IEventPublisher>().Publish(new TabStripCreated(x, "payment-method-edit", this.Html, this.Model));
	})
}

@helper TabGeneral()
{
	@(Html.LocalizedEditor<PaymentMethodEditModel, PaymentMethodLocalizedModel>("paymentmethod-general-localized",
	@<table class="adminContent">
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.Locales[item].FriendlyName)
			</td>
			<td class="adminData">
				@*IMPORTANT: Do not delete, this hidden element contains the id to assign localized values to the corresponding language *@
				@Html.HiddenFor(model => model.Locales[item].LanguageId)

				@Html.EditorFor(model => Model.Locales[item].FriendlyName)
				@Html.ValidationMessageFor(model => model.Locales[item].FriendlyName)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.Locales[item].Description)
			</td>
			<td class="adminData">
				@Html.TextAreaFor(model => Model.Locales[item].Description)
				@Html.ValidationMessageFor(model => model.Locales[item].Description)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.Locales[item].FullDescription)
			</td>
			<td class="adminData wide">
				@Html.EditorFor(model => model.Locales[item].FullDescription, "Html")
				@Html.ValidationMessageFor(model => model.Locales[item].FullDescription)
			</td>
		</tr>
	</table>
	,
	@<table class="adminContent">
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.FriendlyName)
			</td>
			<td class="adminData">
				@Html.EditorFor(model => model.FriendlyName)
				@Html.ValidationMessageFor(model => model.FriendlyName)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.Description)
			</td>
			<td class="adminData">
				@Html.TextAreaFor(model => model.Description)
				@Html.ValidationMessageFor(model => model.Description)
			</td>
		</tr>
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.FullDescription)
			</td>
			<td class="adminData wide">
				@Html.EditorFor(x => x.FullDescription, "Html")
				@Html.ValidationMessageFor(model => model.FullDescription)
			</td>
		</tr>
	</table>
	))

    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.RoundOrderTotalEnabled)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.RoundOrderTotalEnabled)
                @Html.ValidationMessageFor(model => model.RoundOrderTotalEnabled)
            </td>
        </tr>
    </table>
}

@helper TabRestrictions()
{
	if (Model.FilterConfigurationUrls.Count == 0)
	{
		<div class="alert alert-info">
			@T("Admin.Configuration.Payment.Methods.RestrictionNote")
		</div>
	}

	<div>
		<div id="FilterOutPaymentMethodContainer"></div>
	</div>
}

@helper TabStores()
{
	@Html.Partial("StoreSelector", Model)
}

<script type="text/javascript">
	$(document).ready(function () {
		var configUrls = [@Html.Raw(string.Join(", ", Model.FilterConfigurationUrls))],
			i = 0;

		if (configUrls.length > 0) {
			getFilterConfiguration(configUrls[0], $('#FilterOutPaymentMethodContainer'));
		}

		function getFilterConfiguration(url, container) {
			$.ajax({
				url: url,
				cache: false,
				dataType: 'html',
				success: function (html) {
					container.append(html);
					if (++i < configUrls.length)
					{
						getFilterConfiguration(configUrls[i], container);
					}
					applyCommonPlugins(container);
				}
			});
		}
    });
</script>